//
//  RHTestVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/11/14.
//

#import "RHTestVC.h"
#import "RHTestCell.h"

@interface RHTestVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) NSMutableArray *xArr;

@property (nonatomic ,strong) NSMutableArray *yArr_1;

@property (nonatomic ,strong) NSMutableArray *yArr_2;

@property (nonatomic ,strong) NSMutableArray *entryArr;
@end

@implementation RHTestVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
}

-(void)setupUI
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView setEstimatedSectionFooterHeight:0];
    [_tableView setSectionFooterHeight:0];
    [_tableView registerClass:[RHTestCell class] forCellReuseIdentifier:@"RHTestCell"];
    _tableView.estimatedRowHeight = 380;
    [self.view addSubview:_tableView];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];
    

    _xArr = [NSMutableArray array];
    _yArr_1 = [NSMutableArray array];
    _yArr_2 = [NSMutableArray array];
    _entryArr = [NSMutableArray array];
    
    [QMUITips showLoadingInView:self.view];
    kWeakSelf;
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        for (int i = 0; i < 1440; i++) {
            [weakSelf.xArr addObject:@(i)];
            NSInteger y1_value = 150 + arc4random_uniform(20);
            NSInteger y2_value = 50 + arc4random_uniform(20);
            
            ChartDataEntry *entry_1 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y1_value];
            ChartDataEntry *entry_2 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y2_value];
            ChartDataEntry *entry_3 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y1_value];
            ChartDataEntry *entry_4 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y2_value];
            ChartDataEntry *entry_5 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y1_value];
            ChartDataEntry *entry_6 = [[ChartDataEntry alloc] initWithX:i y:(CGFloat)y2_value];
            [weakSelf.entryArr addObject:entry_1];
            [weakSelf.entryArr addObject:entry_2];
            [weakSelf.entryArr addObject:entry_3];
            [weakSelf.entryArr addObject:entry_4];
            [weakSelf.entryArr addObject:entry_5];
            [weakSelf.entryArr addObject:entry_6];
            
            [self.yArr_1 addObject:entry_1];
            [self.yArr_2 addObject:entry_2];
            NSLog(@"------>%ld",i);
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [QMUITips hideAllTipsInView:self.view];
            [weakSelf.tableView reloadData];
           
        });
    });

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (kUI_WINDOW_W-30)*0.6;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"------>返回%ld组 %ld行",indexPath.section,indexPath.row);
//    if(indexPath.row == 4||indexPath.row == 12||indexPath.row ==18){
//        RHTestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHTestCell"];
//        [cell setXArr:self.xArr yArr_1:self.yArr_1 yArr_2:self.yArr_2];
//        return cell;
//    }
    
    RHTestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHTestCell"];
    [cell setXArr:self.xArr yArr_1:self.yArr_1 yArr_2:self.yArr_2];
    return cell;
    return [UITableViewCell new];
}
@end
